﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Kenly.ChineseSegment.Core
{
    /// <summary>
    /// 统计分词比较器。
    /// </summary>
    public class SegmentCounterComparer : IComparer<SegmentCounter>
    {
        private bool _ascend = true;


        public SegmentCounterComparer()
        {
        }

        public SegmentCounterComparer(bool ascend)
        {
            _ascend = ascend;
        }

        #region IComparer<SegmentCountPair> 成员

        public int Compare(SegmentCounter x, SegmentCounter y)
        {
            if (x.Rank != y.Rank)
            {
                return _ascend ? 
                    x.Rank.CompareTo(y.Rank) : y.Rank.CompareTo(x.Rank);
            }

            if (x.Times != y.Times)
            {
                return _ascend ? 
                    (x.Times - y.Times) : (y.Times - x.Times);
            }

            //若次数相同，按默认顺序排序。
            return x.DefaultIndex - y.DefaultIndex;
        }

        #endregion

       
    }
}
